<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model :model="model" :form="form" :rules="rules" ref="form" layout="vertical">
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="日期" prop="time">
              <!--              <a-input placeholder="请输入" v-model="model.time" style="width: 100%" />-->
              <a-date-picker
                v-model:value="time"
                placeholder="选择日期"
                style="width:100%"
                :allowClear="false"
                @change="changeTime"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="车间" prop="workshop">
              <j-dict-select-tag placeholder="请选择车间" v-model="model.workshop" dictCode="workshop" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="班次" prop="classes">
              <j-dict-select-tag placeholder="请选择班次" v-model="model.classes" dictCode="shift" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="上班时间" prop="workHours">
              <a-input-number placeholder="请输入" v-model="model.workHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="机台时间" prop="machineHours">
              <a-input-number placeholder="请输入" v-model="model.machineHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机号" prop="machine">
              <a-input placeholder="请输入" v-model="model.deviceNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机型" prop="machineType">
              <a-input placeholder="请输入" v-model="model.machineType" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="工号" prop="workNoBlockingCar">
              <a-input placeholder="请输入" v-model="model.workNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="姓名" prop="nameBlockingCar">
              <a-input placeholder="请输入" v-model="model.realname" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="专兼职" prop="fullPartTime">
              <a-select
                default-value="true"
                placeholder="请输入"
                v-model="model.fullPartTime"
                style="width: 100%"
                @change="handleChange"
              >
                <a-select-option value="true">
                  是
                </a-select-option>
                <a-select-option value="false">
                  否
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="实际长度" prop="realityLength">
              <a-input placeholder="请输入" v-model="model.realityLength" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="重量(kg)" prop="weight">
              <a-input placeholder="请输入" v-model="model.weight" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="台数" prop="productType">
              <a-input placeholder="请输入" v-model="model.machinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="看台数(8小时)" prop="machinesNumEightHours">
              <a-input placeholder="请输入" v-model="model.machinesNumEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="定额看台" prop="fixedMachinesNum">
              <a-input placeholder="请输入" v-model="model.fixedMachinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="排包数(包)" prop="rowBagsNum">
              <a-input placeholder="请输入" v-model="model.rowBagsNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="滤尘数(台)" prop="dustFilteredNum">
              <a-input placeholder="请输入" v-model="model.dustFilteredNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉打包" prop="cottonBlendPackage">
              <a-input placeholder="请输入" v-model="model.cottonBlendPackage" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉拉包" prop="cottonBlendPullBag">
              <a-input placeholder="请输入" v-model="model.cottonBlendPullBag" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉排包" prop="cottonBlendRowBag">
              <a-input placeholder="请输入" v-model="model.cottonBlendRowBag" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="线单价(线/元)" prop="lineUnitPrice">
              <a-input placeholder="请输入" v-model="model.lineUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="排包单价(包/元)" prop="rowBagUnitPrice">
              <a-input placeholder="请输入" v-model="model.rowBagUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="滤尘单价(台/元)" prop="dustFiltrationUnitPrice">
              <a-input placeholder="请输入" v-model="model.dustFiltrationUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉打包单价(元/包)" prop="cottonBlendingPackageUnitPrice">
              <a-input placeholder="请输入" v-model="model.cottonBlendingPackageUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="混棉拉包单价(元/包)" prop="cottonBlendingPullBagUnitPrice">
              <a-input placeholder="请输入" v-model="model.cottonBlendingPullBagUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉排包单价(元/包)" prop="cottonBlendingRowBagUnitPrice">
              <a-input placeholder="请输入" v-model="model.cottonBlendingRowBagUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="清洁单价(班/元)" prop="cleaningUnitPrice">
              <a-input placeholder="请输入" v-model="model.cleaningUnitPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="看台工资(元)" prop="grandstandWages">
              <a-input placeholder="请输入" v-model="model.grandstandWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="排包工资(元)" prop="rowBagWages">
              <a-input placeholder="请输入" v-model="model.rowBagWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="滤尘工资(元)" prop="dustFilterWages">
              <a-input placeholder="请输入" v-model="model.dustFilterWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉打包工资(元)" prop="cottonBlendingPackageWages">
              <a-input placeholder="请输入" v-model="model.cottonBlendingPackageWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="混棉拉包工资(元)" prop="cottonBlendingPullBagWages">
              <a-input placeholder="请输入" v-model="model.cottonBlendingPullBagWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="混棉排包工资(元)" prop="cottonBlendingRowBagWages">
              <a-input placeholder="请输入" v-model="model.cottonBlendingRowBagWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="清洁工资(元)" prop="cleaningWages">
              <a-input placeholder="请输入" v-model="model.cleaningWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="其它补贴" prop="otherSubsidies">
              <a-input placeholder="请输入" v-model="model.otherSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="合计工资%" prop="totalWages">
              <a-input placeholder="请输入" v-model="model.totalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="机台保养" prop="machinesMaintenance">
              <a-input placeholder="请输入" v-model="model.machinesMaintenance" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="备注" prop="remark">
              <a-input placeholder="请输入" v-model="model.remark" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种数量" prop="varietyNum">
              <a-input placeholder="请输入" v-model="model.varietyNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="车间总额工资" prop="totalWorkshopWages">
              <a-input placeholder="请输入" v-model="model.totalWorkshopWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <!--        <a-row class="form-row" :gutter="16">-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="看台" prop="manageMachines">-->
        <!--              <a-input placeholder="请输入" v-model="model.manageMachines" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="台车时间" prop="machinesCarTime">-->
        <!--              <a-input placeholder="请输入" v-model="model.machinesCarTime" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="台车天时间" prop="machinesCarDayTime">-->
        <!--              <a-input placeholder="请输入" v-model="model.machinesCarDayTime" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--        </a-row>-->
        <!--        <a-row class="form-row" :gutter="16">-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="工号转换" prop="workIdConversion">-->
        <!--              <a-input placeholder="请输入" v-model="model.workIdConversion" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="原单价" prop="originalPrice">-->
        <!--              <a-input placeholder="请输入" v-model="model.originalPrice" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="原工资" prop="originalWages">-->
        <!--              <a-input placeholder="请输入" v-model="model.originalWages" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="现-原" prop="originalNow">-->
        <!--              <a-input placeholder="请输入" v-model="model.originalNow" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--        </a-row>-->
        <!--        <a-row class="form-row" :gutter="16">-->
        <!--          <a-col :span="6">-->
        <!--            <a-form-model-item label="幅度" prop="rangeData">-->
        <!--              <a-input placeholder="请输入" v-model="model.rangeData" style="width: 100%" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--        </a-row>-->
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import JEditor from '@/components/jeecg/JEditor'
import JSwitch from '@/components/jeecg/JSwitch'

import moment from 'moment'
import { getShiftSystem, productTypeSpoolingList, productTypeSpunYarn } from '../../../../api/customApi'
export default {
  name: 'DeviceModal',
  components: {
    JEditor,
    JSwitch
  },
  props: {
    planTime: String
  },
  data() {
    return {
      title: '操作',
      visible: false,
      time: null,
      workHours: null,
      machineHours: null,
      disable: true,
      model: {
        planTime: '',
        workshop: null,
        classes: null,
        workHours: '',
        machineHours: '',
        deviceNo: '',
        workNo: '',
        realname: '',
        machineClassification: '',
        weight: '',
        fixedOutputEightHours: '',
        machinesNum: '',
        machinesNumEightHours: '',
        fixedMachinesNum: '',
        otherSubsidies: '',
        totalWages: '',
        machinesMaintenance: '',
        remark: '',
        fullPartTime: '',
        rowBagsNum: '',
        dustFilteredNum: '',
        cottonBlendPackage: '',
        cottonBlendRowBag: '',
        lineUnitPrice: '',
        rowBagUnitPrice: '',
        dustFiltrationUnitPrice: '',
        cottonBlendingPackageUnitPrice: '',
        cottonBlendingPullBagUnitPrice: '',
        cottonBlendingRowBagUnitPrice: '',
        grandstandWages: '',
        rowBagWages: '',
        dustFilterWages: '',
        cottonBlendingPackageWages: '',
        cottonBlendingPullBagWages: '',
        cottonBlendingRowBagWages: '',
        cleaningWages: '',
        varietyNum: '',
        totalWorkshopWages: '',
        machineType: '',
        realityLength: ''
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        add: '/crm_salary_excel_blowing/crmSalaryExcelBlowing/add'
        // edit: '/crm_salary_excel_blowing/crmSalaryExcelBlowing/edit',
      }
    }
  },
  created() {},
  methods: {
    changeWorkHours(date, dateString) {
      this.model.workHours = dateString + ' 00:00:00'
      // this.model.workHours = new Date(dateString).getTime()
    },
    changeMachineHours(date, dateString) {
      this.model.machineHours = dateString + ' 00:00:00'
      // this.model.machineHours = new Date(dateString).getTime()
    },
    handleChange(e) {
      console.log(e)
    },
    changeProductType(val) {
      productTypeSpoolingList({ id: val }).then(res => {
        // this.model = res.result.records[0]
        this.model.productCategory = res.result.records[0].productCategory
        this.model.productBranch = res.result.records[0].productBranch
        this.model.productTypeCoefficient = res.result.records[0].productTypeCoefficient
        this.model.unitPriceCoefficient = res.result.records[0].unitPriceCoefficient
        this.model.ingots = res.result.records[0].ingots
        this.model.fixedMachinesNum = res.result.records[0].fixedMachinesNum
        this.model.outputPrice = res.result.records[0].outputPrice
        this.model.changeTubeBoxPrice = res.result.records[0].changeTubeBoxPrice
        this.model.originalPrice = res.result.records[0].originalPrice
      })
    },
    changeTime(date, dateString) {
      this.model.planTime = dateString
    },
    add() {
      this.disable = false
      this.model.planTime = this.planTime
      this.time = this.planTime
      this.edit({}, 1)
    },
    edit(record, isEdit) {
      if (isEdit != 1) {
        this.model = Object.assign({}, record)
        this.time = moment(this.model.planTime)
      }

      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.disable = true
      this.$refs.form.resetFields()
      this.model.planTime = ''
      this.model.workshop = null
      this.model.classes = null
      this.model.workHours = ''
      this.model.machineHours = ''
      this.model.deviceNo = ''
      this.model.workNo = ''
      this.model.realname = ''
      this.model.productBranch = ''
      this.model.productTypeCoefficient = ''
      this.model.unitPriceCoefficient = ''
      this.model.comprehensiveCoefficient = ''
      this.model.ingots = ''
      this.model.fixedOutputEightHours = ''
      this.model.machinesNum = ''
      this.model.machinesNumEightHours = ''
      this.model.fixedMachinesNum = ''
      this.model.machinesOutput = ''
      this.model.wagesOutput = ''
      this.model.changeTubeBoxNum = ''
      this.model.changeTubeBoxNumEightHours = ''
      this.model.outputPrice = ''
      this.model.changeTubeBoxPrice = ''
      this.model.changeTubeBoxWages = ''
      this.model.outputWages = ''
      this.model.ingotsNumSubsidies = ''
      this.model.coefficientDeduction = ''
      this.model.otherSubsidies = ''
      this.model.totalWages = ''
      this.model.completionRate = ''
      this.model.machinesMaintenance = ''
      this.model.remark = ''
      this.model.selfSpoolingFixedMachinesRate = ''
      this.model.workingTime = ''
      this.model.manageMachines = ''
      this.model.machinesCarTime = ''
      this.model.machinesCarDayTime = ''
      this.model.workIdConversion = ''
      this.model.originalPrice = ''
      this.model.originalWages = ''
      this.model.originalNow = ''
      this.model.rangeData = ''
    },

    handleOk() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model)
          console.log('formData', formData)
          //时间格式化
          httpAction(httpurl, formData, method)
            .then(res => {
              if (res.success) {
                this.$message.success(res.message != null ? res.message : '执行成功')
                this.$emit('ok')
              } else {
                this.$message.warning(res.message != null ? res.message : '执行失败')
              }
            })
            .finally(() => {
              this.confirmLoading = false
              this.close()
            })
        } else {
          return false
        }
      })
    },

    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped></style>
